$(function() {
    $("#register").click(function() {
        $(".p_tip").hide();
        $(".p_chk").show();
        $("#tip_pwd2").text("请再次输入密码");
        var userId = $("#userId").val().trim();
        var pwd1 = $("#pwd1").val().trim();
        var pwd2 = $("#pwd2").val().trim();
        var realName = $("#realName").val().trim();
        var sex = $("#sex").val().trim();
        var certNum = $("#certNum").val().trim();
        var linkTel = $("#linkTel").val().trim();
        var mail = $("#mail").val().trim();
        var userType = $("#userType").val().trim();
        // alert(userId+","+pwd1+","+pwd2+","+realName+","+sex+","+certNum+","+linkTel+","+email+","+userType);

        if (checkIsEmpty(userId, "#tip_userId", "#chk_userId", 3)) {
            return;
        }
        if (checkIsEmpty(pwd1, "#tip_pwd1", "#chk_pwd1", 6)) {
            return;
        }
        if (checkIsEmpty(pwd2, "#tip_pwd2", "#chk_pwd2", 6)) {
            return;
        }
        if (pwd1 != (pwd2)) {
            $("#tip_pwd2").text("两次输入的密码不一致,请确认!");
            checkIsEmpty("", "#tip_pwd2", "#chk_pwd2");
            return;
        }

        if (checkIsEmpty(realName, "#tip_realName", "#chk_realName")) {
            return;
        }
        if (checkIsEmpty(certNum, "#tip_certNum", "#chk_certNum", 18)) {
            return;
        }
        if (checkIsEmpty(linkTel, "#tip_linkTel", "#chk_linkTel")) {
            return;
        }
        if (checkIsEmpty(mail, "#tip_mail", "#chk_mail")) {
            return;
        }
        $.ajax({
            url : "/SofaGuest/login/register.do",
            type : "post",
            data : {
                "userId" : userId,
                "pwd" : pwd1,
                "realName" : realName,
                "sex" : sex,
                "certNum" : certNum,
                "linkTel" : linkTel,
                "mail" : mail,
                "userType" : userType
            },
            dataType : "json",
            success : function(result) {
                alert(result.detial);
                if (result.status == "0000") {
                    window.location.href = "index.html";
                }
            },
            error : function() {
                alert("系统异常,请稍后重试!");
            }
        });
    });
});
